package com.dajiba.demo;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.SizeUtils;

@SuppressLint("AppCompatCustomView")
public class CustomTextRound extends TextView {
    Paint mPaint = new Paint();
    RectF mRectF = new RectF();

    public CustomTextRound(Context context) {
        super(context);
        init();
    }

    public CustomTextRound(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public CustomTextRound(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        mPaint.setColor(Color.WHITE);
        mPaint.setAntiAlias(true);
    }

    int mRound = SizeUtils.dp2px(10);

    public void setBgColor(int color) {
        mPaint.setColor(color);
    }

    public void setRound(int round) {
        mRound = round;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        mRectF.set(0, 0, getWidth(), getHeight());
        canvas.drawRoundRect(mRectF, mRound, mRound, mPaint);
        super.onDraw(canvas);
    }
}
